package nus.mtech.presentation;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;

import nus.mtech.constant.PresentationConstant;
 
/**
 * <p>Title</p>
 * <p>Copyright (c) 2011 NUS ISS.  All rights reserved. </p>
 * @author Jiang Hao Min
 * @version 1.0
 *
 * <p align='left'>
 * <table border='1' width='80%'>
 *   <tr>
 *     <th colspan='4'>Change History</th>
 *   </tr>
 *   <tr>
 *     <td><u>Version</u></td>
 *     <td><u>Name</u></td>
 *     <td><u>Date</u></td>
 *     <td><u>Remarks</u></td>
 *   </tr>
 *   <tr>
 *     <td>1.0</td>
 *     <td>Jiang Hao Min</td>
 *     <td>Mar 25, 2011</td>
 *     <td>Creation of the class.</td>
 *   </tr>
 * </table>
 * </p>
 */

public class LogoutPanel extends JPanel implements ActionListener {
	private static final long serialVersionUID = -8390777252548216213L;
	
	private static volatile LogoutPanel INSTANCE;
	private JLabel lblWelcome;
	private JButton btnLogout;
	
	public LogoutPanel(){
		super(null);
		this.setBackground(PresentationConstant.CONSOLE_BACKGROUND);
		this.setPreferredSize(new Dimension(1004, 643));
		initialization();
	}
	
	public void initialization() {
		JLabel borderBase = new JLabel();
		borderBase.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
		borderBase.setBounds(40, 71, 944, 342);
		add(borderBase);
		
		lblWelcome = new JLabel();
		lblWelcome.setBounds(105, 133, 106, 14);
		add(lblWelcome);
		
		btnLogout = new JButton("Logout");
		btnLogout.setBounds(457, 331, 89, 23);
		btnLogout.addActionListener(this);
		add(btnLogout);
	}
	
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btnLogout) {
			if(null != Console.getLoginUser()){
				Console.setLoginUser(null);
			}
			clearAllPanel();
			Console.initLoginComponent();
		}
	}

	private void clearAllPanel(){
		CustomerPanel.getInstance().clear();
		ComplaintPanel.getInstance().clear();
		DigitalPanel.getInstance().clear();
		MobilePanel.getInstance().clear();
		CableTVPanel.getInstance().clear();
		ViewBillPanel.getInstance().clear();
	}
	
	public static LogoutPanel getInstance(){
		synchronized(LogoutPanel.class){
			if (null == INSTANCE) {
				INSTANCE = new LogoutPanel();
			}
			return INSTANCE;
		}
	}

	public JLabel getLblWelcome() {
		return lblWelcome;
	}
}
